﻿using DBModel.Entity;
using Microsoft.EntityFrameworkCore;

namespace DBModel.EntityExtension
{
    public static class EntityContextExtension
    {
        public static void RegisterBasicEntity(this ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BasicUserInfo>(entity =>
            {
                entity.ToTable(nameof(BasicUserInfo));
                entity.HasKey(s => s.Id);
                entity.Property(s => s.LongId).IsRequired();
                entity.HasIndex(s => s.LongId).HasDatabaseName("uk_LongId").IsUnique();
                entity.HasIndex(s => s.IdCard).HasDatabaseName("uk_IdCard").IsUnique();
                entity.Property(s => s.Name).HasMaxLength(50);
                entity.Property(s => s.Nickname).HasMaxLength(100);
                entity.Property(s => s.Passwd).HasMaxLength(100);
                entity.Property(s => s.Email).HasMaxLength(50);
                entity.Property(s => s.Phone).HasMaxLength(50);
                entity.Property(s => s.Photo).HasMaxLength(200);
                entity.Property(s => s.State);
                entity.Property(s => s.Gender);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
                entity.Property(s => s.LockStamp);
            });

            modelBuilder.Entity<BusinessOrderInfo>(entity =>
            {
                entity.ToTable(nameof(BusinessOrderInfo));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.OrderId);
                entity.Property(s => s.TotalPrice);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
            });

            modelBuilder.Entity<BusinessOrderProduct>(entity =>
            {
                entity.ToTable(nameof(BusinessOrderProduct));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.OrderId);
                entity.Property(s => s.ProductId);
                entity.Property(s => s.ProductNum);
                entity.Property(s => s.ProductRealPrice);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
            });

            modelBuilder.Entity<BusinessProductInfo>(entity =>
            {
                entity.ToTable(nameof(BusinessProductInfo));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.Name);
                entity.Property(s => s.Image);
                entity.Property(s => s.Price);
                entity.Property(s => s.Description);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
            });

            modelBuilder.Entity<BusinessProductInventory>(entity =>
            {
                entity.ToTable(nameof(BusinessProductInventory));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.ProductId);
                entity.Property(s => s.Count);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
            });

            modelBuilder.Entity<PaymentBankInfo>(entity =>
            {
                entity.ToTable(nameof(PaymentBankInfo));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.BankCode);
                entity.Property(s => s.BankName);
                entity.Property(s => s.BankPayAddress);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
            });

            modelBuilder.Entity<PaymentOrderInfo>(entity =>
            {
                entity.ToTable(nameof(PaymentOrderInfo));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.OrderGuid);
                entity.Property(s => s.OrderStrId);
                entity.Property(s => s.OrderPrice);
                entity.Property(s => s.PayPrice);
                entity.Property(s => s.TotalPrice);
                entity.Property(s => s.PayMode);
                entity.Property(s => s.BankId);
                entity.Property(s => s.CreateTime);
                entity.Property(s => s.ModefyTime);
            });

            modelBuilder.Entity<VipInfo>(entity =>
            {
                entity.ToTable(nameof(VipInfo));
                entity.HasKey(s => s.Id).HasName($"pk_id");
                entity.Property(s => s.Name);
                entity.Property(s => s.Start);
                entity.Property(s => s.End);
                entity.Property(s => s.VipLevel);
                entity.Property(s => s.VipType);
                entity.Property(s => s.IdNum);
            });

        }

    }
}